package cake.srcprojector.parser;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;

import cake.srcprojector.AbstractJSONWriter;
import cake.srcprojector.DocParser;
import cake.srcprojector.DocParserContext;
import cake.srcprojector.model.Page;
import cake.srcprojector.service.PageService;


public class IndexDocParser extends AbstractJSONWriter implements DocParser {

	private PageService pageService = new PageService();
	
	
	public IndexDocParser(OutputStream outputStream) throws IOException {
		super(outputStream);
	}


	@Override
	public void startFolder(File folder, DocParserContext docParserContext) throws IOException {

	}

	
	@Override
	public void parsePage(File pageFile, File[] subFolderArray, DocParserContext docParserContext) throws IOException {
		Page page = pageService.parsePage(pageFile);
		
		write("{");
		writeAttribute("pageid", page.getPageId());
		write(",");
		writeAttribute("path", pageFile.getPath());
		write("}");
		write(",");
	}

	
	@Override
	public void endFolder(File folder, boolean isLast) throws IOException {

	}

	
}
